﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _12._4
{
    internal class Farm<T> : IEnumerable<T> where T : Animal
    {
        private List<T> animals=new List<T>();
        public List<T> Animals
        {
            get { return animals; }
        }

        public IEnumerator<T> GetEnumerator()
        {
            return animals.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
           return animals.GetEnumerator();
        }
        public void MakeNoisee()
        {
            foreach (T t in Animals)
            {
                t.MakeANoise();
            }
        }

        public void FeedTheAnimals()
        {
            foreach (T t in animals)
            {
                t.Feed();
            }
        }


        public Farm<Cow> GetCows()
        {
            Farm<Cow> CowFarm= new Farm<Cow>();
            foreach (T t in animals)
            {
                if(t is Cow)
                {
                    CowFarm.animals.Add(t as Cow);
                }
            }
            return CowFarm;
        }
    }
}
